package xin.xinny.common;

import org.springframework.http.HttpStatus;

/**
 * rest接口返回数据对象
 */
public class Result {
	/**
	 * 结果0-失败，1-成功
	 */
	private int ret;
	/**
	 * 结果代码
	 */
	private int code;
	/**
	 * 结果消息
	 */
	private String msg;
	/**
	 * 结果数据
	 */
	private Object data;

/*	@JSONField(serialize = false)
	private Throwable exception;*/

	public static final int SUCCESS = 1;
	public static final int FAILURE = 0;

	public Result(int ret, int code, String msg, Object data) {
		super();
		this.code = code;
		this.msg = msg;
		this.ret = ret;
		this.data = data;
	}

	public Result(int ret, String msg) {
		this.ret = ret;
		this.msg = msg;
	}

	public Result(int ret, String msg, Object data) {
		this.ret = ret;
		this.msg = msg;
		this.data = data;
	}

	public Result(int ret, HttpStatus status) {
		this.code = status.value();
		this.msg = status.getReasonPhrase();
		this.ret = ret;
	}

	public Result() {
		super();
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public int getRet() {
		return ret;
	}
	public void setRet(int ret) {
		this.ret = ret;
	}
	public Object getData() {
		return data;
	}
	public void setData(Object data) {
		this.data = data;
	}

	public void setException(Throwable e) {
		this.msg = e.getMessage()==null?e.toString():e.getMessage();
	}
}
